package com.simplegovern.authority.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.simpleframe.security.AbstractLoginAction;
import com.simpleframe.security.User;
import com.simplegovern.authority.service.UserRoleService;
import com.simplegovern.authority.service.UserService;

//@ParentPackage(value="demo-default")
//@ParentPackage(value="struts-default")
//@Namespace("/")
//@Action("/login")
@Results({   
    @Result(name = "input", location = "login.jsp"),  
    @Result(name = "success", location = "main.shtml", type="redirect")
})
@Scope("prototype")
public class LoginAction extends AbstractLoginAction {
	@Autowired
	private UserService us;
	@Autowired
	private UserRoleService urs;
	
	@Override
	protected User getUser() throws Exception{
		return (User)us.getSysUserByName(username);
	}

	@Override
	protected List<Long> getRoles(Long id) throws Exception {
		return urs.getRolesByUserId(id);
	}
	
	@Override
	protected void loginCommit() throws Exception {
		//登录成功后，会被调用
		
	}
	
	@Override
	protected void logoutCommit() throws Exception {
		//登出后，会被调用
		
	}
}
